package com.rivulet.foreign.controller;

import com.rivulet.foreign.pojo.Message;
import com.rivulet.foreign.service.MessageService;
import com.rivulet.foreign.tools.Lock;
import com.rivulet.foreign.tools.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * {message功能}
 *
 * @author xujiac
 * @create 2021/6/3
 * @since 1.0.0
 */
@Controller
@RequestMapping(value = "/message")
public class MessageController {

    final
    MessageService messageService;

    public MessageController(MessageService messageService) {
        this.messageService = messageService;
    }

    @RequestMapping(value = "/send")
    @ResponseBody
    public Results messageSend(@RequestBody Message message, @CookieValue("user_id") String user_id) {
        message.setUser_id(Lock.lockOff(user_id));
        message.setUptime(new Date());
        Results results = messageService.setMessage(message);
        return results;
    }

    @RequestMapping(value = "/check")
    @ResponseBody
    public Results messageCheck() {
        Results results = messageService.getAllMessage();
        return results;
    }

    @RequestMapping(value = "/check/{page}")
    public Results messageCheck(@PathVariable("page") Integer page) {
        return null;
    }
}
